/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.client.company.gui;

import org.toools.gwt.widget.client.bc.BusinessObjectPanel;
import org.toools.gwt.widget.client.bc.StringAttribute;
import org.toools.gwt.wmc.jpa.Company;

/**
 *
 * @author Manuel
 */
public class CompanyPanel extends BusinessObjectPanel {

    private StringAttribute name = null;

    public CompanyPanel (Object cp) {
        super(cp,2);

        name = new StringAttribute("company name", false);
        name.setMaxLength(100);

        this.add(name);

        recreateContent();
        preselect();
        validate();

         setStatus("* missing or invalid input");
    }

    @Override
    public void map() {
         if (getBusinessObject() == null) {
            setBusinessObject(new Company());
        }
        Company c = (Company) getBusinessObject();
        c.setName(name.getAttributeValue().toString());
    }

    @Override
    public void preselect() {
        if (getBusinessObject() != null) {
            Company c = (Company) getBusinessObject();
            name.setAttributeValue(c.getName());
        } else {
            name.setAttributeValue("");
        }
    }

}
